package com.lz.ovuola.util.redis.cluster;

import java.io.Serializable;

import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

//@Configuration
public class CustomClusterRedisTemplate {
	// @Resource(name = "redisClusterConnectionFactoryConfig")
	private RedisConnectionFactory redisClusterConnectionFactoryConfig;
	// @Resource
	private HessianSerializer hessianSerializer;

	// @Bean
	public RedisTemplate<String, Serializable> redisTemplate() {
		RedisTemplate<String, Serializable> redisTemplate = new RedisTemplate<String, Serializable>();
		redisTemplate.setConnectionFactory(redisClusterConnectionFactoryConfig);
		redisTemplate.setKeySerializer(new StringRedisSerializer());
		// redisTemplate.setValueSerializer(hessianSerializer);
		redisTemplate.setHashKeySerializer(hessianSerializer); // 最好也使用默认
		redisTemplate.setHashValueSerializer(hessianSerializer);
		return redisTemplate;
	}

}